package com.ywl.lambda;

import java.util.function.IntBinaryOperator;

/**
 * 使用lambda练习二
 *
 * @author 24040
 * @name LambdaDemo01
 * @date 2022-08-21 16:30
 */
public class LambdaDemo02 {

    public static void main(String[] args) {
        add();
    }

    public static int calculateNum(IntBinaryOperator operator){
        int a = 10;
        int b = 20;
        return operator.applyAsInt(a, b);
    }


    /**
     * 加法
     * @return
     */
    public static int add() {
        //匿名内部类的写法
        /*int result = calculateNum(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                System.out.println(left + "+" + right + "=" + (left + right));
                return left + right;
            }
        });*/

        //lambda表达式
        int result = calculateNum((left, right) -> {
            System.out.println(left + "+" + right + "=" + (left + right));
            return left + right;
        });
        return result;
    }
}
